<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 76053
  Date: 2020/3/17
  Time: 15:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>处理修改密码页面</title>
</head>
<body>
<%
    String pas=request.getParameter("pas");
    String pass=request.getParameter("pass");

    Connection con=null;
    try {
        /*1.加载*/
        Class.forName("com.mysql.jdbc.Driver");

        /*2.建立连接*/
        String url="jdbc:mysql://localhost:3306/wl18301";
        String db_user="root";
        String db_password="root";
        con= DriverManager.getConnection(url,db_user,db_password);

        /*1.验证旧密码是不是对的*/
        String sql="SELECT * FROM student WHERE s_password=?";
        PreparedStatement pre=con.prepareStatement(sql);
        pre.setString(1,pas);
        ResultSet se=pre.executeQuery();
        if(se!=null){
            String sql2="UPDATE student SET  s_password=?,update_time=?  WHERE s_id=?";
            PreparedStatement pre2=con.prepareStatement(sql2);
            pre2.setString(1,pass);

            pre2.setDate(2,new Date(new java.util.Date().getTime()) );

            pre2.setInt(3,(int)session.getAttribute("id"));
            int i= pre2.executeUpdate();
            if(i>0){
                    out.print("您修改密码成功!");
            }

        }else{
            response.sendRedirect("updatePassword.jsp");
        }


    }catch (ClassNotFoundException e){
        e.printStackTrace();
    }catch (SQLException e){
        e.printStackTrace();
    }finally {
        if(con!=null){
            con.close();
        }
    }





%>



</body>
</html>
